local ClientOHOH = _G.ClientOHOH
local M = ClientOHOH.class.new(script,ClientOHOH.files.OHOHOLYBUIBase())
local CallBackManager =  ClientOHOH.load.CallBackManager()
local ConnectClass = _G.CommonOHOH.load.Connect()
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
function M.new(...)
    return M(...)
end

function Initsts(ui)
    ui.insts = {}
    ui.insts.root = "ctrl.root"
    ui.insts.count = "ctrl.Text"
    ui.insts.brick = "ctrl.brick"
end


function M.ctor(self)
    Initsts(self)
    M.super.ctor(self,ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.BrickGui"))
end

---------------外部调用接口-------------
function M.SetText(self,count)
    --需要配置表文字
    self.insts.count.Text = count
    self:TweenShake(self.insts.root,1.5,0.2)
    self:TweenShake(self.insts.brick,1,0.3)
end

function M.TweenShake(self,target,ratio,speed)
    if ratio == nil then
        ratio =1
    end
    self.insts.root.Rotation = 0
    local tweenInfo = TweenInfo.new(
        speed,
        Enum.EasingStyle.Quart,
        Enum.EasingDirection.Out,
        0,
        false,
        0
    )
    
    local tweenLeftInfo = {
        Rotation = math.random(-5,-3)*ratio
    }

    local tweenRightInfo = {
        Rotation = math.random(3,5)*ratio
    }

    local tweenOriginInfo = {
        Rotation = 0
    }


    local tweenLeft = TweenService:Create(target,tweenInfo,tweenLeftInfo)
    local tweenRight = TweenService:Create(target,tweenInfo,tweenRightInfo)
    local tweenOrigin = TweenService:Create(target,tweenInfo,tweenOriginInfo)

    tweenLeft:Play()
    tweenLeft.Completed:Connect(function()
        tweenRight:Play()
    end)
    tweenRight.Completed:Connect(function()
        tweenOrigin:Play()
    end)
end

--返回图标的世界坐标
function M.GetWorldPosition(self)
    local screenPos = self.insts.root.AbsolutePosition
    local ray = camera:ScreenPointToRay(screenPos.X, screenPos.Y)
    -- 定义射线的长度和方向
    local distance = 50 -- 射线的长度，可以根据需要调整
    local rayDirection = ray.Direction * distance

    -- 计算世界坐标
    local worldPos = ray.Origin + rayDirection
    return worldPos

end

function M.dtor(self)
    M.super.dtor(self)
end


return M